import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import { viteStaticCopy } from 'vite-plugin-static-copy';

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    host: 'myproxy.com',
    port: 8003,
    open: true,
    cors: true,
    proxy: {
      '/api': {
        target: 'api.host.com',
        changeOrigin: true,
        secure: false,
        rewrite: path => path.replace(/^\/api/, ''),
        configure: (proxy, options) => {
          proxy.on('proxyReq', (proxyReq, req, res) => {
            console.log('Request:', req.method, req.url)
          })
          proxy.on('proxyRes', (proxyRes, req, res) => {
            console.log('Response:', proxyRes.statusCode, req.url)
          })
        }
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    //amis相关文件直接复制
    viteStaticCopy({
      targets: [
        {
          src: `${path.resolve(__dirname, './node_modules/amis/sdk').replace(/\\/g, '/')}/[!.]*`,
          dest: 'amis/sdk',
        }
      ]
    })
  ]
})
